package edu.nuc.rubikstopwatch;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class Preferences {
	private static final String KEY_IS_SHOW_PWD_TIP="KISPT";
	private static SharedPreferences sharedPreferences;
	private static Context context;
	private static Preferences instance;
	
	public static Preferences getInstance(Context c){
		context = c;
		if(instance == null){
			instance = new Preferences();
		}
		return instance;
	}
	
	public boolean closeShowPwdTip(){
		Editor editor = getEditor();
		editor.putBoolean(KEY_IS_SHOW_PWD_TIP, false);
		return editor.commit();
	}
	
	public boolean openShowPwdTip(){
		Editor editor = getEditor();
		editor.putBoolean(KEY_IS_SHOW_PWD_TIP, true);
		return editor.commit();
	}
	
	public Editor getEditor(){
		SharedPreferences pref = getSharedPreferences();
		return pref.edit();
	}
	
	private SharedPreferences getSharedPreferences(){
		if(sharedPreferences == null){
			sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		}
		return sharedPreferences;
	}
	
	//判断是否选择了“不再显示”，如果选择了，返回false
	public boolean isShowPwdTip(){
		return getSharedPreferences().getBoolean(KEY_IS_SHOW_PWD_TIP, true);
	}
}
